<template>
  <div v-enter-helper="getList" class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-row>

          <el-form
            ref="dataList2"
            :inline="true"
            :model="listQuery"
            class="demo-form-inline"
          >
            <el-form-item label="">
              <el-select
                v-model="listQuery.evaluate"
                clearable
                filterable
                placeholder="请选择评分"
              >
                <el-option
                  v-for="item in  grades"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="">
              <el-input
                v-model.number="listQuery.user_id"
                clearable
                placeholder="用户ID"
                type="text"
              ></el-input>
            </el-form-item>
            <el-form-item label="">
              <el-input
                v-model.number="listQuery.grades_id"
                clearable
                placeholder="主播ID"
                type="text"
              ></el-input>
            </el-form-item>
            <el-form-item label="">
              <el-select
                v-model="listQuery.connection_id"
                clearable
                filterable
                placeholder="请选择音色"
              >
                <el-option
                  v-for="item in adminOptions"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-date-picker
                v-model="date"
                clearable
                end-placeholder="结束日期"
                range-separator="至"
                start-placeholder="开始日期"
                type="datetimerange"
                value-format="yyyy-MM-dd HH:mm:ss"
                @change="handleChangeData"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="searchSubmit">查询</el-button>
              <el-button type="primary" @click="resetSubmit">重置</el-button>
            </el-form-item>
          </el-form>
        </el-row>
      </div>
      <div class="item">
        <el-table
          ref="dataList"
          v-loading="listLoading"
          :data="menuList"
          :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
          border
          row-key="id"
          style="width:100%;margin-bottom: 20px;"
        >
          <!-- <el-table-column type="selection"></el-table-column> -->
          <el-table-column label="ID" prop="id"></el-table-column>
          <el-table-column label="音色" prop="name"></el-table-column>
          <el-table-column label="主播ID" prop="anchor_code"></el-table-column>
          <el-table-column label="主播名称" prop="anchor_name"></el-table-column>
          <el-table-column label="用户ID" prop="user_code"></el-table-column>
          <el-table-column label="用户名称" prop="user_name"></el-table-column>
          <el-table-column label="订单金额" prop="coin"></el-table-column>
          <el-table-column label="时长" prop="time"></el-table-column>
          <el-table-column label="评分" prop="evaluate_value"></el-table-column>
          <el-table-column
            label="时间"
            prop="created_at"
          ></el-table-column>
          <el-table-column label="操作" width="100px">
            <template slot-scope="scope">
              <el-button
                plain
                size="mini"
                type="primary"
                @click="handleDetail(scope.row)"
              >查看详情
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <cus-pagination
          :limit.sync="listQuery.perPage"
          :page.sync="listQuery.page"
          :total="total"
          @pagination="getList"
        />
      </div>
    </el-card>
    <!-- 删除弹框 -->
    <el-dialog
      :visible.sync="deleteDialogVisible"
      title="确定删除吗?"
      width="435px"
    >
      <span style=""
      ><em style="font-style:normal;color:red">删除后不可恢复</em
      >，你还要继续吗？</span
      >
      <span slot="footer" class="dialog-footer">
        <el-button @click="deleteDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmDelete">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { matchListData } from '../../api/connectLine/mathchRecord'
import { listData } from '../../api/connectLine/soundStyle'

export default {
  data() {
    return {
      confirmBtn: false,
      adminOptions: [],
      grades: [
        {
          id: '1',
          name: '普通'
        },
        {
          id: '2',
          name: '心动'
        },
        {
          id: '0',
          name: '无评分'
        },
        {
          id: '',
          name: '不限'
        },
      ],
      deleteDialogVisible: false,
      listLoading: false,
      menuList: [],
      total: 10,
      date: null,
      listQuery: {
        page: 1,
        perPage: 10,
        connection_id: undefined,
        user_id: undefined,
        anchor_id: undefined,
        time_start: undefined,
        time_end: undefined
      },
      dataIds: ''
    }
  },
  created() {
    this.getList()
    this.getSoundStyleList()
  },
  methods: {
    async getSoundStyleList() {
      const { data: { list } } = await listData()
      this.adminOptions = list
    },
    async getList() {
      for (let key in this.listQuery) {
          this.listQuery[key] = this.listQuery[key] === '' ? undefined : this.listQuery[key]
      }
      const res = await matchListData(this.listQuery)
      this.menuList = res.data.list
      this.total = res.data.total
      this.confirmBtn = false
    },
    handleChangeData(value) {
      if (!value) {
        this.listQuery.time_start = undefined
        this.listQuery.time_end = undefined
      } else if (value && value.length === 2) {
        this.listQuery.time_start = value[0]
        this.listQuery.time_end = value[1]
      }
    },
    // 查询
    searchSubmit() {
      this.listQuery.page = 1
      this.getList()
    },
    // 重置
    resetSubmit() {
      this.date = null
      this.listQuery = {
        page: 1,
        perPage: 10,
        connection_id: undefined,
        user_id: undefined,
        anchor_id: undefined,
        time_start: undefined,
        time_end: undefined
      },
        this.getList()
    },
    // 点击单个删除
    handleDetail(row) {
      // this.dataIds = { ids: row.id.toString() }
      // this.deleteDialogVisible = true
      this.$router.push({
        path: '/connectLine/matchRecordDetail',
        query: { id: row.id }
      })
    },
    // 确定删除
    confirmDelete() {
      if (this.confirmBtn) return
      this.confirmBtn = true
      // this.dataIds)
      this.deleteDialogVisible = false
      deleteData(this.dataIds).then(response => {
        if (response.code === 200) {
          this.getList()
          this.deleteDialogVisible = false
          this.$notify({
            type: 'success',
            message: '操作成功',
            position: 'bottom-right',
            showClose: false,
            duration: 3000
          })
        } else {
          this.confirmBtn = false
        }
      })
    }
  }
}
</script>

<style scoped>
[v-cloak] {
  display: none;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}

.box-card {
  width: 100%;
}

.demo-form-inline {
  /* float: right; */
}

/deep/ .el-card__header {
  padding-bottom: 0;
}
</style>
